const path = require('path');
const webpack = require('webpack');
const _ = require('lodash/object');
const getEntryObj = require('./webpack_entry_config')
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const extractSass = new ExtractTextPlugin({
    filename: "../css/[name].css",
    disable: process.env.NODE_ENV === "development"
});

module.exports = {
    entry: _.assign(getEntryObj('test'), {
        common : ['babel-polyfill', './mod/lib/zepto.min.js']
    }),
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist/js/'),
        publicPath: '/dist/js/'
    },
    module: {
        rules: [{
            test: /\.scss$/,
            use: extractSass.extract({
                use: [{
                    loader: "css-loader"
                }, {
                    loader: "sass-loader"
                }],
                // 在开发环境使用 style-loader
                fallback: "style-loader"
            })
        }, {
            test: /\.(png|jpg|gif|svg|eot|woff|ttf)$/,
            loader: 'file-loader',
            options: {
                name: '[name].[ext]?[hash]'
            }
        }, {
            test: /\.js$/,
            exclude: /(node_modules|bower_components)/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['env', 'stage-0'],
                    plugins: ['transform-runtime']
                }
            }
        }]
    },

    plugins: [
        //  new webpack.optimize.UglifyJsPlugin({
        //    compress: process.env.NODE_ENV === 'production'
        //  }),
        extractSass,
        new webpack.optimize.CommonsChunkPlugin({
            name: 'common',
            minChunks: Infinity
        })
    ]
}